home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / srch_rs.exe / SEARCH.ASM < prev    next >
Assembly Source File  |  1992-01-17  |  3KB  |  65 lines

  1.  IDEAL
  2.  LOCALS
  3.  MODEL TPASCAL
  4.  CODESEG
  5. PROC FindByte FAR _Data : DWORD, _Size : WORD, Num : BYTE
  6. PUBLIC FindByte
  7. ;function FindByte(var Data; Size : word; Num : byte) : word; external;
  8.  mov       al,[Num]          ; Load search byte
  9.  mov       cx,[_Size]        ; Load size
  10.  les       di,[_Data]        ; Load address into es:di
  11.  cld                         ; Scan forward
  12.  repne     scas [Num]        ; Search for the sucker
  13.  jne       @@NotFound        ; Not Found
  14.  mov       ax,[_Size]        ; Load size
  15.  sub       ax,cx             ; Subtract
  16.  ret                         ; Done
  17. @@NotFound:
  18.  xor       ax,ax             ; Return 0
  19.  ret                         ; Exit
  20. ENDP FindByte
  21.  
  22. PROC StrPos FAR _Data : DWORD, _Size : WORD, _St : DWORD
  23. ; function StrPos (var Data; Size : word; St : string) : word;
  24. PUBLIC StrPos
  25.  push      ds                ; Save DS register
  26.  cld                         ; Go forward
  27.  lds       si,[_St]          ; Load ds:si with the String
  28.  les       di,[_Data]        ; Load es:di with the array
  29.  lodsb                       ; Load al with size of _St
  30.  xor       ah,ah             ; Convert al to word ax
  31.  mov       bx,[_Size]        ; Load size of array
  32.  sub       bx,ax             ; Compare string sizes
  33.  jb        @@NotFound        ; String larger so not found
  34.  push      bp                ; Save bp
  35.  inc       bx                ; stop at zero not after 0
  36.  mov       dx,di             ; Offset into _Data
  37.  mov       bp,si             ; Start of _St
  38.                              ; ax  String size
  39.                              ; bx  Comparisons left to make
  40.                              ; dx  Offset into _Data
  41.                              ; bp  Start of _St, bp no longer needed
  42. @@Compare:
  43.  mov       cx,ax             ; Load string size
  44.  mov       di,dx             ; Current location within _Data
  45.  mov       si,bp             ; Start of _St
  46.  repz      cmpsb             ; Compare the suckers
  47.  jz        @@Found           ; Eureka!
  48.  inc       dx                ; Next position
  49.  dec       bx                ; One fell down, 99 bottles of beer...
  50.  jnz       @@Compare         ; No more bottles of beer on the wall
  51. @@NotFound:
  52.  pop       bp                ; Restore bp
  53.  xor       ax,ax             ; Return 0
  54.  jmp       @@Done            ; Get 'otta here
  55. @@Found:
  56.  pop       bp                ; Restore bp
  57.  mov       ax,dx            
  58.  sub       ax,[WORD _Data]   ; Subtract starting offset
  59.  inc       ax                ; Increment for base of 1 not 0
  60. @@Done:
  61.  pop       ds                ; Restor DS register
  62.  ret                         ; Done
  63. ENDP StrPos
  64. END
  65.